package com.futures.investm.common;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.futures.investm.R;
import com.futures.investm.constant.BussConstant;
import com.aries.ui.view.title.TitleBarView;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.SaveCallback;

import butterknife.BindView;
import tech.com.commoncore.base.BaseTitleActivity;
import tech.com.commoncore.utils.DataUtils;
import tech.com.commoncore.utils.ToastUtil;

public class FeedbackActivity extends BaseTitleActivity {


    @BindView(R.id.et_feedback)
    EditText etFeedback;

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("反馈")
                .setRightText("提交")
                .setOnRightTextClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //立即反馈
                        String content = etFeedback.getText().toString().trim();
                        if (DataUtils.isEmptyString(content)) {
                            ToastUtil.show("亲,内容不能为空哟...");
                            return;
                        }


                        AVObject feedback = new AVObject(BussConstant.TABLE_FEEDBACK);
                        feedback.put(BussConstant.USER,AVUser.getCurrentUser());
                        feedback.put(BussConstant.CONTENT, content);
                        feedback.saveInBackground(new SaveCallback() {
                            @Override
                            public void done(AVException e) {
                                if (e == null) {
                                    ToastUtil.show("感谢您的反馈。");
                                    etFeedback.setText("");
                                    FeedbackActivity.this.finish();
                                } else {
                                    ToastUtil.show("反馈失败,请检查网络是否正常。");
                                }
                            }
                        });
                    }
                });
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_feedback;
    }

    @Override
    public void initView(Bundle savedInstanceState) {

    }
}
